package com.jhc.drone.communication.datagram.receive;


import cn.hutool.json.JSONObject;
import com.jhc.drone.communication.datagram.ack.Ack;
import com.jhc.drone.communication.enums.CameraEnum;
import com.jhc.drone.communication.enums.FlyModeEnum;
import com.jhc.drone.communication.enums.SystemStatusEnum;
import com.jhc.drone.communication.mavlink.MAVLinkPacket;
import com.jhc.drone.communication.mavlink.Messages.MAVLinkMessage;
import com.jhc.drone.communication.mavlink.camera.*;
import com.jhc.drone.communication.mavlink.common.*;
import com.jhc.drone.communication.mavlink.custom1.msg_custom_msg1;
import com.jhc.drone.communication.mavlink.custom2.msg_custom_msg2;
import com.jhc.drone.communication.mavlink.minimal.msg_heartbeat;
import com.jhc.drone.communication.mavlink.mission1.msg_mission_msg1;
import com.jhc.drone.communication.mavlink.safeguard.msg_safeguard_msg;
import com.jhc.drone.communication.mavlink.serialNumber.msg_drone_serial_number;
import com.jhc.drone.communication.mavlink.supplement.msg_ins_supplement;
import com.jhc.drone.communication.network.cache.DroneCache;
import com.jhc.drone.communication.ws.WsDto;
import com.jhc.drone.communication.ws.WsEndpoint;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Objects;

/**
 * @author lcp
 * @date 2025年01月2025/1/15 9:48
 * @describe
 */
@Slf4j
public class Receiver {

    public static void parse(Channel channel, MAVLinkPacket mavLinkPacket) {
        //获取对应策略对象
        MAVLinkMessage unpack = mavLinkPacket.unpack();
        //解析数据
        unpack.unpack(mavLinkPacket.payload);
//        log.info("数据包类型: {}", unpack.name());
        switch (unpack.name()) {
            case "MAVLINK_MSG_ID_DRONE_SERIAL_NUMBER":
                msg_drone_serial_number serialNumber = (msg_drone_serial_number) unpack;
                DroneCache.SERIAL_NUMBER_MAP.put(channel, serialNumber.getSerial_Number());
                break;
            case "MAVLINK_MSG_ID_HEARTBEAT": // base_mode最高位是1或者0判断是否解锁，（0加锁，1解锁）
                msg_heartbeat msg_heartbeat = (msg_heartbeat) unpack;
                boolean isArmed = (msg_heartbeat.base_mode & 0x8000) != 0;
                //  log.info("----------心跳-isArmed:{}----------", isArmed);
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("arm_mode_status").setDescription("是否解锁、飞行模式、系统状态")
                        .setObject("is_armed", isArmed ? "已解锁" : "已锁定",
                                "fly_mode", FlyModeEnum.getModel(msg_heartbeat.custom_mode).getName(),
                                "system_status", SystemStatusEnum.getModel(msg_heartbeat.system_status).getName()));
                if (!DroneCache.CHANNEL_MAP.containsKey(msg_heartbeat.sysid)) {
                    DroneCache.CHANNEL_MAP.put(msg_heartbeat.sysid, channel);
                }
                if (DroneCache.SERIAL_NUMBER_MAP.containsKey(channel)) {
                    String serialNum = DroneCache.SERIAL_NUMBER_MAP.get(channel);
                    DroneCache.ON_LINE.put(serialNum, true);
                    DroneCache.FLY_MODE_MAP.put(serialNum,FlyModeEnum.getModel(msg_heartbeat.custom_mode));
                }
                break;
            case "MAVLINK_MSG_ID_GPS_RAW_INT":
                msg_gps_raw_int gps = (msg_gps_raw_int) unpack;
                //gps
                // log.info("飞控gps数据-> int32_t经度: {}, int32_t纬度:{} 高度:{}米 GPS地面速度:{}cm/s 卫星数量:{} 时间:{}", gps.lat, gps.lon, (gps.alt / 1000), gps.vel, gps.satellites_visible, DateUtil.date());
                JSONObject entries = new JSONObject();
                entries.set("satellites_num", gps.satellites_visible);
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("satellites_num").setDescription("卫星数量").setValue(entries.toString()));
                break;
            case "MAVLINK_MSG_ID_SYS_STATUS":
                msg_sys_status status = (msg_sys_status) unpack;
                break;
            case "MAVLINK_MSG_ID_SYSTEM_TIME":
                msg_system_time time = (msg_system_time) unpack;
                break;
            case "MAVLINK_MSG_ID_PING":
                msg_ping ping = (msg_ping) unpack;
                break;
            case "MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL":
                msg_change_operator_control control = (msg_change_operator_control) unpack;
                break;
            case "MAVLINK_MSG_ID_CHANGE_OPERATOR_CONTROL_ACK":
                msg_change_operator_control_ack ack = (msg_change_operator_control_ack) unpack;
                break;
            case "MAVLINK_MSG_ID_AUTH_KEY":
                msg_auth_key authKey = (msg_auth_key) unpack;
                break;
            case "MAVLINK_MSG_ID_LINK_NODE_STATUS":
                msg_link_node_status nodeStatus = (msg_link_node_status) unpack;
                break;
            case "MAVLINK_MSG_ID_SET_MODE":
                msg_set_mode setMode = (msg_set_mode) unpack;
                break;
//                case "MAVLINK_MSG_ID_PARAM_ACK_TRANSACTION":
//                    msg_param_ack_transaction status = (msg_param_ack_transaction) unpack;
//                    break;
            case "MAVLINK_MSG_ID_PARAM_REQUEST_READ":
                msg_param_request_read read = (msg_param_request_read) unpack;
                break;
            case "MAVLINK_MSG_ID_PARAM_REQUEST_LIST":
                msg_param_request_list requestList = (msg_param_request_list) unpack;
                break;
            case "MAVLINK_MSG_ID_PARAM_VALUE":
                msg_param_value paramValue = (msg_param_value) unpack;
                break;
            case "MAVLINK_MSG_ID_PARAM_SET":
                msg_param_set paramSet = (msg_param_set) unpack;
                break;
            case "MAVLINK_MSG_ID_GPS_STATUS":
                msg_gps_status gpsStatus = (msg_gps_status) unpack;
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("dbm_gps_num").setDescription("卫星数量、信道干扰强弱")
                        .setObject("gps_num", gpsStatus.satellites_visible, "satellite_snr", gpsStatus.satellites_visible));
                break;
            case "MAVLINK_MSG_ID_SCALED_IMU":
                msg_scaled_imu scaledImu = (msg_scaled_imu) unpack;
                break;
            case "MAVLINK_MSG_ID_RAW_IMU": // IMU
                msg_raw_imu rawImu = (msg_raw_imu) unpack;
                break;
            case "MAVLINK_MSG_ID_RAW_PRESSURE":
                msg_raw_pressure pressure = (msg_raw_pressure) unpack;
                break;
            case "MAVLINK_MSG_ID_SCALED_PRESSURE":
                msg_scaled_pressure scaledPressure = (msg_scaled_pressure) unpack;
                break;
            case "MAVLINK_MSG_ID_ATTITUDE":// 翻滚角、偏航角、俯仰角、翻滚速度等
                msg_attitude attitude = (msg_attitude) unpack;
                float yawValue = attitude.yaw < 0 ? 360 + (180 / 3.1f) * attitude.yaw : (180 / 3.1f) * attitude.yaw;
                WsDto wsDto = new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel))
                        .setFlag("roll_yaw")
                        .setDescription("无人机飞行角度")
                        .setObject("roll_angle", attitude.roll, "yaw_angle", attitude.yaw, "pitch_angle", attitude.pitch, "currentYaw", yawValue);
                WsEndpoint.sendMessage(wsDto);
                break;
            case "MAVLINK_MSG_ID_ATTITUDE_QUATERNION":
                msg_attitude_quaternion quaternion = (msg_attitude_quaternion) unpack;
                break;
            case "MAVLINK_MSG_ID_LOCAL_POSITION_NED": // x/y/z
                msg_local_position_ned positionNed = (msg_local_position_ned) unpack;
                double levelDistance = Math.sqrt(Math.pow(positionNed.x, 2) + Math.pow(positionNed.y, 2));
                double homeDistance = Math.sqrt(Math.pow(positionNed.x, 2) + Math.pow(positionNed.y, 2) + Math.pow(positionNed.z, 2));
                double levelSpeed = Math.sqrt(Math.pow(positionNed.vx, 2) + Math.pow(positionNed.vy, 2));
                double verticalSpeed = Math.sqrt(Math.pow(positionNed.vz, 2) + Math.pow(positionNed.vy, 2));
                BigDecimal levelDis = new BigDecimal(levelDistance).setScale(3, RoundingMode.HALF_UP);
                BigDecimal homeDis = new BigDecimal(homeDistance).setScale(3, RoundingMode.HALF_UP);
                BigDecimal levelSp = new BigDecimal(levelSpeed).setScale(3, RoundingMode.HALF_UP);
                BigDecimal verticalSp = new BigDecimal(verticalSpeed).setScale(3, RoundingMode.HALF_UP);

                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("distance_speed")
                        .setDescription("无人机飞行速度、飞行距离（level_distance:水平距离，home_distance:飞行距离）").setObject("level_distance", levelDis.doubleValue(),
                                "home_distance", homeDis.doubleValue(), "level_speed", levelSp.doubleValue(), "vertical_speed", verticalSp.doubleValue()));
                break;
            case "MAVLINK_MSG_ID_GLOBAL_POSITION_INT": //  经纬度、高度、海拔
                msg_global_position_int positionInt = (msg_global_position_int) unpack;
                int lon = positionInt.lon;
                int lat = positionInt.lat;
                double pow = Math.pow(10, 7);
                double heightPow = Math.pow(10, 3);
                BigDecimal lonValue = new BigDecimal(lon / pow).setScale(7, RoundingMode.HALF_UP);
                BigDecimal latValue = new BigDecimal(lat / pow).setScale(7, RoundingMode.HALF_UP);
                BigDecimal altValue = new BigDecimal(positionInt.relative_alt / heightPow).setScale(7, RoundingMode.HALF_UP);
                double currentHeight = altValue.doubleValue();
                if (DroneCache.SERIAL_NUMBER_MAP.containsKey(channel)) {
                    Double v = DroneCache.HOME_MAP.get(DroneCache.SERIAL_NUMBER_MAP.get(channel));
                    currentHeight = Objects.isNull(v) ? 0 : v + altValue.doubleValue();
                }
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("lon_lat_height")
                        .setObject("lon", lonValue.doubleValue(), "lat", latValue, "height", altValue.doubleValue(), "currentHeight", currentHeight)
                        .setDescription("经度维度高度"));
                break;
            case "MAVLINK_MSG_ID_RC_CHANNELS_SCALED":
                msg_rc_channels_scaled scaled = (msg_rc_channels_scaled) unpack;
                break;
            case "MAVLINK_MSG_ID_RC_CHANNELS_RAW":
                msg_rc_channels_raw channelsRaw = (msg_rc_channels_raw) unpack;
                break;
            case "MAVLINK_MSG_ID_SERVO_OUTPUT_RAW":
                msg_servo_output_raw outputRaw = (msg_servo_output_raw) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_REQUEST_PARTIAL_LIST":
                msg_mission_request_partial_list partialList = (msg_mission_request_partial_list) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_WRITE_PARTIAL_LIST":
                msg_mission_write_partial_list writePartialList = (msg_mission_write_partial_list) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_ITEM":
                msg_mission_item msgMissionItem = (msg_mission_item) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_REQUEST":
                msg_mission_request missionRequest = (msg_mission_request) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_SET_CURRENT":
                msg_mission_set_current msgMissionSetCurrent = (msg_mission_set_current) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_CURRENT":
                msg_mission_current msgMissionCurrent = (msg_mission_current) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_REQUEST_LIST":
                msg_mission_request_list msgMissionRequestList = (msg_mission_request_list) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_COUNT":
                msg_mission_count msgMissionCount = (msg_mission_count) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_CLEAR_ALL":
                msg_mission_clear_all msgMissionClearAll = (msg_mission_clear_all) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_ITEM_REACHED":
                msg_mission_item_reached msgMissionItemReached = (msg_mission_item_reached) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_ACK":
                msg_mission_ack msgMissionAck = (msg_mission_ack) unpack;
                Ack.ack(msgMissionAck);
                break;
            case "MAVLINK_MSG_ID_SET_GPS_GLOBAL_ORIGIN":
                msg_set_gps_global_origin gpsGlobalOrigin = (msg_set_gps_global_origin) unpack;
                break;
            case "MAVLINK_MSG_ID_GPS_GLOBAL_ORIGIN":
                msg_gps_global_origin gpsGlobalOrigin1 = (msg_gps_global_origin) unpack;
                break;
            case "MAVLINK_MSG_ID_PARAM_MAP_RC":
                msg_param_map_rc paramMapRc = (msg_param_map_rc) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_REQUEST_INT":
                msg_mission_request_int missionRequestInt = (msg_mission_request_int) unpack;
                Ack.ack(missionRequestInt);
                break;
//                case "MAVLINK_MSG_ID_MISSION_CHECKSUM":
//                    msg_mission_checksum status = (msg_mission_checksum) unpack;
//                    break;
            case "MAVLINK_MSG_ID_SAFETY_SET_ALLOWED_AREA":
                msg_safety_set_allowed_area safetySetAllowedArea = (msg_safety_set_allowed_area) unpack;
                break;
            case "MAVLINK_MSG_ID_SAFETY_ALLOWED_AREA":
                msg_safety_allowed_area safetyAllowedArea = (msg_safety_allowed_area) unpack;
                break;
            case "MAVLINK_MSG_ID_ATTITUDE_QUATERNION_COV":
                msg_attitude_quaternion_cov attitudeQuaternionCov = (msg_attitude_quaternion_cov) unpack;
                break;
            case "MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT":
                msg_nav_controller_output navControllerOutput = (msg_nav_controller_output) unpack;
                break;
            case "MAVLINK_MSG_ID_GLOBAL_POSITION_INT_COV":
                msg_global_position_int_cov globalPositionIntCov = (msg_global_position_int_cov) unpack;
                break;
            case "MAVLINK_MSG_ID_LOCAL_POSITION_NED_COV":
                msg_local_position_ned_cov localPositionNedCov = (msg_local_position_ned_cov) unpack;
                break;
            case "MAVLINK_MSG_ID_RC_CHANNELS": //遥控器通道值
                msg_rc_channels rcChannels = (msg_rc_channels) unpack;
                break;
            case "MAVLINK_MSG_ID_REQUEST_DATA_STREAM":
                msg_request_data_stream requestDataStream = (msg_request_data_stream) unpack;
                break;
            case "MAVLINK_MSG_ID_DATA_STREAM":
                msg_data_stream dataStream = (msg_data_stream) unpack;
                break;
            case "MAVLINK_MSG_ID_MANUAL_CONTROL":
                msg_manual_control msgManualControl = (msg_manual_control) unpack;
                break;
            case "MAVLINK_MSG_ID_RC_CHANNELS_OVERRIDE":
                msg_rc_channels_override rcChannelsOverride = (msg_rc_channels_override) unpack;
                break;
            case "MAVLINK_MSG_ID_MISSION_ITEM_INT":
                msg_mission_item_int msgMissionItemInt = (msg_mission_item_int) unpack;
                break;
            case "MAVLINK_MSG_ID_VFR_HUD":
                msg_vfr_hud vfrHud = (msg_vfr_hud) unpack;
                break;
            case "MAVLINK_MSG_ID_COMMAND_INT":
                msg_command_int commandInt = (msg_command_int) unpack;
                break;
            case "MAVLINK_MSG_ID_COMMAND_LONG":
                msg_command_long commandLong = (msg_command_long) unpack;
                break;
            case "MAVLINK_MSG_ID_COMMAND_ACK":
                msg_command_ack commandAck = (msg_command_ack) unpack;
                Ack.ack(commandAck);
                break;
            case "MAVLINK_MSG_ID_COMMAND_CANCEL":
                msg_command_cancel commandCancel = (msg_command_cancel) unpack;
                break;
            case "MAVLINK_MSG_ID_MANUAL_SETPOINT":
                msg_manual_setpoint msgManualSetpoint = (msg_manual_setpoint) unpack;
                break;
            case "MAVLINK_MSG_ID_SET_ATTITUDE_TARGET":
                msg_set_attitude_target setAttitudeTarget = (msg_set_attitude_target) unpack;
                break;
            case "MAVLINK_MSG_ID_ATTITUDE_TARGET": // 目标姿态
                msg_attitude_target attitudeTarget = (msg_attitude_target) unpack;
                break;
            case "MAVLINK_MSG_ID_SET_POSITION_TARGET_LOCAL_NED":
                msg_set_position_target_local_ned targetLocalNed = (msg_set_position_target_local_ned) unpack;
                break;
            case "MAVLINK_MSG_ID_POSITION_TARGET_LOCAL_NED":
                msg_position_target_local_ned positionTargetLocalNed = (msg_position_target_local_ned) unpack;
                break;
            case "MAVLINK_MSG_ID_SET_POSITION_TARGET_GLOBAL_INT":
                msg_set_position_target_global_int setPositionTargetGlobalInt = (msg_set_position_target_global_int) unpack;
                break;
            case "MAVLINK_MSG_ID_POSITION_TARGET_GLOBAL_INT":
                msg_position_target_global_int positionTargetGlobalInt = (msg_position_target_global_int) unpack;
                break;
            case "MAVLINK_MSG_ID_LOCAL_POSITION_NED_SYSTEM_GLOBAL_OFFSET":
                msg_local_position_ned_system_global_offset globalOffset = (msg_local_position_ned_system_global_offset) unpack;
                break;
            case "MAVLINK_MSG_ID_HIL_STATE":
                msg_hil_state hilState = (msg_hil_state) unpack;
                break;
            case "MAVLINK_MSG_ID_HIL_CONTROLS":
                msg_hil_controls hilControls = (msg_hil_controls) unpack;
                break;
            case "MAVLINK_MSG_ID_HIL_RC_INPUTS_RAW":
                msg_hil_rc_inputs_raw inputsRaw = (msg_hil_rc_inputs_raw) unpack;
                break;
            case "MAVLINK_MSG_ID_HIL_ACTUATOR_CONTROLS":
                msg_hil_actuator_controls actuatorControls = (msg_hil_actuator_controls) unpack;
                break;
            case "MAVLINK_MSG_ID_OPTICAL_FLOW":
                msg_optical_flow opticalFlow = (msg_optical_flow) unpack;
                break;
            case "MAVLINK_MSG_ID_GLOBAL_VISION_POSITION_ESTIMATE":
                msg_global_vision_position_estimate golobalVisionPositionEstimate = (msg_global_vision_position_estimate) unpack;
                break;
            case "MAVLINK_MSG_ID_VISION_POSITION_ESTIMATE":
                msg_vision_position_estimate visionPositionEstimate = (msg_vision_position_estimate) unpack;
                break;
            case "MAVLINK_MSG_ID_VISION_SPEED_ESTIMATE":
                msg_vision_speed_estimate visionSpeedEstimate = (msg_vision_speed_estimate) unpack;
                break;
            case "MAVLINK_MSG_ID_VICON_POSITION_ESTIMATE":
                msg_vicon_position_estimate viconPositionEstimate = (msg_vicon_position_estimate) unpack;
                break;
            case "MAVLINK_MSG_ID_HIGHRES_IMU":
                msg_highres_imu highresImu = (msg_highres_imu) unpack;
                break;
            case "MAVLINK_MSG_ID_OPTICAL_FLOW_RAD":
                msg_optical_flow_rad opticalFlowRad = (msg_optical_flow_rad) unpack;
                break;
            case "MAVLINK_MSG_ID_HIL_SENSOR":
                msg_hil_sensor sensor = (msg_hil_sensor) unpack;
                break;
            case "MAVLINK_MSG_ID_SIM_STATE":
                msg_sim_state simState = (msg_sim_state) unpack;
                break;
            case "MAVLINK_MSG_ID_RADIO_STATUS":
                msg_radio_status radioStatus = (msg_radio_status) unpack;
                break;
            case "MAVLINK_MSG_ID_FILE_TRANSFER_PROTOCOL":
                msg_file_transfer_protocol transferProtocol = (msg_file_transfer_protocol) unpack;
                break;
            case "MAVLINK_MSG_ID_TIMESYNC":
                msg_timesync timesync = (msg_timesync) unpack;
                break;
            case "MAVLINK_MSG_ID_CAMERA_TRIGGER":
                msg_camera_trigger cameraTrigger = (msg_camera_trigger) unpack;
                break;
            case "MAVLINK_MSG_ID_HIL_GPS":
                msg_hil_gps hilGps = (msg_hil_gps) unpack;
                break;
            case "MAVLINK_MSG_ID_HIL_OPTICAL_FLOW":
                msg_hil_optical_flow hilOpticalFlow = (msg_hil_optical_flow) unpack;
                break;
            case "MAVLINK_MSG_ID_HIL_STATE_QUATERNION":
                msg_hil_state_quaternion hilStateQuaternion = (msg_hil_state_quaternion) unpack;
                break;
            case "MAVLINK_MSG_ID_SCALED_IMU2":
                msg_scaled_imu2 scaledImu2 = (msg_scaled_imu2) unpack;
                break;
            case "MAVLINK_MSG_ID_LOG_REQUEST_LIST":
                msg_log_request_list logRequestList = (msg_log_request_list) unpack;
                break;
            case "MAVLINK_MSG_ID_LOG_ENTRY":
                msg_log_entry msgLogEntry = (msg_log_entry) unpack;
                break;
            case "MAVLINK_MSG_ID_LOG_REQUEST_DATA":
                msg_log_request_data logRequestData = (msg_log_request_data) unpack;
                break;
            case "MAVLINK_MSG_ID_LOG_DATA":
                msg_log_data logData = (msg_log_data) unpack;
                break;
            case "MAVLINK_MSG_ID_LOG_ERASE":
                msg_log_erase logErase = (msg_log_erase) unpack;
                break;
            case "MAVLINK_MSG_ID_LOG_REQUEST_END":
                msg_log_request_end logRequestEnd = (msg_log_request_end) unpack;
                break;
            case "MAVLINK_MSG_ID_GPS_INJECT_DATA":
                msg_gps_inject_data injectData = (msg_gps_inject_data) unpack;
                break;
            case "MAVLINK_MSG_ID_GPS2_RAW":
                msg_gps2_raw gps2Raw = (msg_gps2_raw) unpack;
                break;
            case "MAVLINK_MSG_ID_POWER_STATUS":
                msg_power_status powerStatus = (msg_power_status) unpack;
                break;
            case "MAVLINK_MSG_ID_SERIAL_CONTROL":
                msg_serial_control serialControl = (msg_serial_control) unpack;
                break;
            case "MAVLINK_MSG_ID_GPS_RTK":
                msg_gps_rtk gpsRtk = (msg_gps_rtk) unpack;
                break;
            case "MAVLINK_MSG_ID_GPS2_RTK":
                msg_gps2_rtk gps2Rtk = (msg_gps2_rtk) unpack;
                break;
            case "MAVLINK_MSG_ID_SCALED_IMU3":
                msg_scaled_imu3 scaledImu3 = (msg_scaled_imu3) unpack;
                break;
            case "MAVLINK_MSG_ID_DATA_TRANSMISSION_HANDSHAKE":
                msg_data_transmission_handshake transmissionHandshake = (msg_data_transmission_handshake) unpack;
                break;
            case "MAVLINK_MSG_ID_ENCAPSULATED_DATA":
                msg_encapsulated_data encapsulatedData = (msg_encapsulated_data) unpack;
                break;
            case "MAVLINK_MSG_ID_DISTANCE_SENSOR":
                msg_distance_sensor distanceSensor = (msg_distance_sensor) unpack;
                break;
            case "MAVLINK_MSG_ID_TERRAIN_REQUEST":
                msg_terrain_request terrainRequest = (msg_terrain_request) unpack;
                break;
            case "MAVLINK_MSG_ID_TERRAIN_DATA":
                msg_terrain_data terrainData = (msg_terrain_data) unpack;
                break;
            case "MAVLINK_MSG_ID_TERRAIN_CHECK":
                msg_terrain_check terrainCheck = (msg_terrain_check) unpack;
                break;
            case "MAVLINK_MSG_ID_TERRAIN_REPORT":
                msg_terrain_report terrainReport = (msg_terrain_report) unpack;
                break;
            case "MAVLINK_MSG_ID_SCALED_PRESSURE2":
                msg_scaled_pressure2 scaledPressure2 = (msg_scaled_pressure2) unpack;
                break;
            case "MAVLINK_MSG_ID_ATT_POS_MOCAP":
                msg_att_pos_mocap attPosMocap = (msg_att_pos_mocap) unpack;
                break;
            case "MAVLINK_MSG_ID_SET_ACTUATOR_CONTROL_TARGET":
                msg_set_actuator_control_target setActuatorControlTarget = (msg_set_actuator_control_target) unpack;
                break;
            case "MAVLINK_MSG_ID_ACTUATOR_CONTROL_TARGET":
                msg_actuator_control_target actuatorControlTarget = (msg_actuator_control_target) unpack;
                break;
            case "MAVLINK_MSG_ID_ALTITUDE":
                msg_altitude msgAltitude = (msg_altitude) unpack;
                break;
            case "MAVLINK_MSG_ID_RESOURCE_REQUEST":
                msg_resource_request resourceRequest = (msg_resource_request) unpack;
                break;
            case "MAVLINK_MSG_ID_SCALED_PRESSURE3":
                msg_scaled_pressure3 scaledPressure3 = (msg_scaled_pressure3) unpack;
                break;
            case "MAVLINK_MSG_ID_FOLLOW_TARGET":
                msg_follow_target followTarget = (msg_follow_target) unpack;
                break;
            case "MAVLINK_MSG_ID_CONTROL_SYSTEM_STATE":
                msg_control_system_state systemState = (msg_control_system_state) unpack;
                break;
            case "MAVLINK_MSG_ID_BATTERY_STATUS": // 电池：电压、电流、温度、消耗
                msg_battery_status batteryStatus = (msg_battery_status) unpack;
                double three = Math.pow(10, 3);
                BigDecimal temp = new BigDecimal(batteryStatus.temperature / three).setScale(3, RoundingMode.HALF_UP);
                int sum = Arrays.stream(batteryStatus.voltages).sum();
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("battery_status").setObject("battery_temp", temp.doubleValue(),
                        "battery_vol", sum, "remain_power", batteryStatus.battery_remaining));
                break;
            case "MAVLINK_MSG_ID_AUTOPILOT_VERSION":
                msg_autopilot_version autopilotVersion = (msg_autopilot_version) unpack;
                break;
            case "MAVLINK_MSG_ID_LANDING_TARGET":
                msg_landing_target landingTarget = (msg_landing_target) unpack;
                break;
//                case "MAVLINK_MSG_ID_SENSOR_OFFSETS":
//                    msg_sensor_offsets status = (msg_sensor_offsets) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_SET_MAG_OFFSETS":
//                    msg_set_mag_offsets status = (msg_set_mag_offsets) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_MEMINFO":
//                    msg_meminfo status = (msg_meminfo) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_AP_ADC":
//                    msg_ap_adc status = (msg_ap_adc) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_DIGICAM_CONFIGURE":
//                    msg_digicam_configure status = (msg_digicam_configure) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_DIGICAM_CONTROL":
//                    msg_digicam_control status = (msg_digicam_control) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_MOUNT_CONFIGURE":
//                    msg_mount_configure status = (msg_mount_configure) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_MOUNT_CONTROL":
//                    msg_mount_control status = (msg_mount_control) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_MOUNT_STATUS":
//                    msg_mount_status status = (msg_mount_status) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_FENCE_POINT":
//                    msg_fence_point status = (msg_fence_point) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_FENCE_FETCH_POINT":
//                    msg_fence_fetch_point status = (msg_fence_fetch_point) unpack;
//                    break;
            case "MAVLINK_MSG_ID_FENCE_STATUS":
                msg_fence_status fenceStatus = (msg_fence_status) unpack;
                break;
//                case "MAVLINK_MSG_ID_AHRS":
//                    msg_ahrs status = (msg_ahrs) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_SIMSTATE":
//                    msg_simstate status = (msg_simstate) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_HWSTATUS":
//                    msg_hwstatus status = (msg_hwstatus) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_RADIO":
//                    msg_radio status = (msg_radio) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_LIMITS_STATUS":
//                    msg_limits_status status = (msg_limits_status) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_WIND":
//                    msg_wind status = (msg_wind) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_DATA16":
//                    msg_data16 status = (msg_data16) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_DATA32":
//                    msg_data32 status = (msg_data32) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_DATA64":
//                    msg_data64 status = (msg_data64) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_DATA96":
//                    msg_data96 status = (msg_data96) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_RANGEFINDER":
//                    msg_rangefinder status = (msg_rangefinder) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_AIRSPEED_AUTOCAL":
//                    msg_airspeed_autocal status = (msg_airspeed_autocal) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_RALLY_POINT":
//                    msg_rally_point status = (msg_rally_point) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_RALLY_FETCH_POINT":
//                    msg_rally_fetch_point status = (msg_rally_fetch_point) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_COMPASSMOT_STATUS":
//                    msg_compassmot_status status = (msg_compassmot_status) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_AHRS2":
//                    msg_ahrs2 status = (msg_ahrs2) unpack;
//                    break;
            case "MAVLINK_MSG_ID_CAMERA_STATUS":
                msg_camera_status cameraStatus = (msg_camera_status) unpack;
                //WsEndpoint.sendMessage(new WsDto().setFlag("battery_status").setObject("",cameraStatus.));
                break;
            case "MAVLINK_MSG_ID_CAMERA_FEEDBACK":
                msg_camera_feedback cameraFeedback = (msg_camera_feedback) unpack;
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("camera_angle").setDescription("云台角度(翻滚、俯仰、偏航)")
                        .setObject("roll_angle", cameraFeedback.roll, "yaw_angle", cameraFeedback.yaw, "pitch_angle", cameraFeedback.pitch));
                break;
            case "MAVLINK_MSG_ID_CAMERA_CAPTURE_STATUS":
                msg_camera_capture_status cameraCaptureStatus = (msg_camera_capture_status) unpack;
                break;
            case "MAVLINK_MSG_ID_CAMERA_FOV_STATUS":
                msg_camera_fov_status cameraFovStatus = (msg_camera_fov_status) unpack;
                break;
            case "MAVLINK_MSG_ID_CAMERA_IMAGE_CAPTURED":
                msg_camera_image_captured cameraImageCaptured = (msg_camera_image_captured) unpack;
                break;
            case "MAVLINK_MSG_ID_CAMERA_INFORMATION":
                msg_camera_information cameraInformation = (msg_camera_information) unpack;
                break;
            case "MAVLINK_MSG_ID_CAMERA_SETTINGS":
                msg_camera_settings cameraSettings = (msg_camera_settings) unpack;
                // zoomLevel变焦级别
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("camera_mode_level").setDescription("云台模式、变焦倍数")
                        .setObject("model", CameraEnum.getModel(cameraSettings.mode_id)
                                , "zoom_level", cameraSettings.zoomLevel));
                break;
            case "MAVLINK_MSG_ID_CAMERA_THERMAL_RANGE":
                msg_camera_thermal_range cameraThermalRange = (msg_camera_thermal_range) unpack;
                break;
            case "MAVLINK_MSG_ID_CAMERA_TRACKING_GEO_STATUS":
                msg_camera_tracking_geo_status cameraTrackingGeoStatus = (msg_camera_tracking_geo_status) unpack;
                break;
            case "MAVLINK_MSG_ID_CAMERA_TRACKING_IMAGE_STATUS":
                msg_camera_tracking_image_status cameraTrackingImageStatus = (msg_camera_tracking_image_status) unpack;
                break;
//                case "MAVLINK_MSG_ID_BATTERY2":
//                    msg_battery2 status = (msg_battery2) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_AHRS3":
//                    msg_ahrs3 status = (msg_ahrs3) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_AUTOPILOT_VERSION_REQUEST":
//                    msg_autopilot_version_request status = (msg_autopilot_version_request) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_REMOTE_LOG_DATA_BLOCK":
//                    msg_remote_log_data_block status = (msg_remote_log_data_block) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_REMOTE_LOG_BLOCK_STATUS":
//                    msg_remote_log_block_status status = (msg_remote_log_block_status) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_LED_CONTROL":
//                    msg_led_control status = (msg_led_control) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_MAG_CAL_PROGRESS":
//                    msg_mag_cal_progress status = (msg_mag_cal_progress) unpack;
//                    break;
            case "MAVLINK_MSG_ID_MAG_CAL_REPORT":
                msg_mag_cal_report calReport = (msg_mag_cal_report) unpack;
                break;
//                case "MAVLINK_MSG_ID_EKF_STATUS_REPORT":
//                    msg_ekf_status_report status = (msg_ekf_status_report) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_PID_TUNING":
//                    msg_pid_tuning status = (msg_pid_tuning) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_DEEPSTALL":
//                    msg_deepstall status = (msg_deepstall) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_GIMBAL_REPORT":
//                    msg_gimbal_report status = (msg_gimbal_report) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_GIMBAL_CONTROL":
//                    msg_gimbal_control status = (msg_gimbal_control) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_GIMBAL_TORQUE_CMD_REPORT":
//                    msg_gimbal_torque_cmd_report status = (msg_gimbal_torque_cmd_report) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_GOPRO_HEARTBEAT":
//                    msg_gopro_heartbeat status = (msg_gopro_heartbeat) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_GOPRO_GET_REQUEST":
//                    msg_gopro_get_request status = (msg_gopro_get_request) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_GOPRO_GET_RESPONSE":
//                    msg_gopro_get_response status = (msg_gopro_get_response) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_GOPRO_SET_REQUEST":
//                    msg_gopro_set_request status = (msg_gopro_set_request) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_GOPRO_SET_RESPONSE":
//                    msg_gopro_set_response status = (msg_gopro_set_response) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_NAV_FILTER_BIAS":
//                    msg_nav_filter_bias status = (msg_nav_filter_bias) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_RADIO_CALIBRATION":
//                    msg_radio_calibration status = (msg_radio_calibration) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_UALBERTA_SYS_STATUS":
//                    msg_ualberta_sys_status status = (msg_ualberta_sys_status) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_COMMAND_INT_STAMPED":
//                    msg_command_int_stamped status = (msg_command_int_stamped) unpack;
//                    break;
//                case "MAVLINK_MSG_ID_COMMAND_LONG_STAMPED":
//                    msg_command_long_stamped status = (msg_command_long_stamped) unpack;
//                    break;
            case "MAVLINK_MSG_ID_EFI_STATUS":
                msg_efi_status efiStatus = (msg_efi_status) unpack;
                break;
//                case "MAVLINK_MSG_ID_RPM":
//                    msg_rpm status = (msg_rpm) unpack;
//                    break;
            case "MAVLINK_MSG_ID_ESTIMATOR_STATUS":
                msg_estimator_status estimatorStatus = (msg_estimator_status) unpack;
                break;
            case "MAVLINK_MSG_ID_WIND_COV":
                msg_wind_cov windCov = (msg_wind_cov) unpack;
                break;
            case "MAVLINK_MSG_ID_GPS_INPUT":
                msg_gps_input gpsInput = (msg_gps_input) unpack;
                break;
            case "MAVLINK_MSG_ID_GPS_RTCM_DATA":
                msg_gps_rtcm_data rtcmData = (msg_gps_rtcm_data) unpack;
                break;
            case "MAVLINK_MSG_ID_HIGH_LATENCY":
                msg_high_latency latency = (msg_high_latency) unpack;
                break;
            case "MAVLINK_MSG_ID_HIGH_LATENCY2":
                msg_high_latency2 latency2 = (msg_high_latency2) unpack;
                break;
            case "MAVLINK_MSG_ID_VIBRATION":
                msg_vibration vibration = (msg_vibration) unpack;
                break;
            case "MAVLINK_MSG_ID_HOME_POSITION":
                msg_home_position homePosition = (msg_home_position) unpack;
                JSONObject object = new JSONObject();
                object.set("home_point", homePosition.altitude);
                if (DroneCache.SERIAL_NUMBER_MAP.containsKey(channel)) {
                    DroneCache.HOME_MAP.put(DroneCache.SERIAL_NUMBER_MAP.get(channel), (double) homePosition.altitude);
                }
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("home_point").setDescription("站点海拔高度").setValue(object.toString()));
                break;
            case "MAVLINK_MSG_ID_SET_HOME_POSITION":
                msg_set_home_position setHomePosition = (msg_set_home_position) unpack;
                break;
            case "MAVLINK_MSG_ID_MESSAGE_INTERVAL":
                msg_message_interval messageInterval = (msg_message_interval) unpack;
                break;
            case "MAVLINK_MSG_ID_EXTENDED_SYS_STATE":
                msg_extended_sys_state sysState = (msg_extended_sys_state) unpack;
                break;
            case "MAVLINK_MSG_ID_ADSB_VEHICLE":
                msg_adsb_vehicle adsbVehicle = (msg_adsb_vehicle) unpack;
                break;
            case "MAVLINK_MSG_ID_COLLISION":
                msg_collision collision = (msg_collision) unpack;
                break;
            case "MAVLINK_MSG_ID_V2_EXTENSION":
                msg_v2_extension v2Extension = (msg_v2_extension) unpack;
                break;
            case "MAVLINK_MSG_ID_MEMORY_VECT":
                msg_memory_vect msgMemoryVect = (msg_memory_vect) unpack;
                break;
            case "MAVLINK_MSG_ID_DEBUG_VECT":
                msg_debug_vect debugVect = (msg_debug_vect) unpack;
                break;
            case "MAVLINK_MSG_ID_NAMED_VALUE_FLOAT":
                msg_named_value_float valueFloat = (msg_named_value_float) unpack;
                break;
            case "MAVLINK_MSG_ID_NAMED_VALUE_INT":
                msg_named_value_int valueInt = (msg_named_value_int) unpack;
                break;
            case "MAVLINK_MSG_ID_STATUSTEXT":
                msg_statustext statustext = (msg_statustext) unpack;
                break;
            case "MAVLINK_MSG_ID_DEBUG":
                msg_debug debug = (msg_debug) unpack;
                break;
            // case "MAVLINK_MSG_ID_Custom_MSG1":
            case "MAVLINK_MSG_ID_CUSTOM_MSG1":
                msg_custom_msg1 customMsg1 = (msg_custom_msg1) unpack;
                break;
            // case "MAVLINK_MSG_ID_Custom_MSG2":
            case "MAVLINK_MSG_ID_CUSTOM_MSG2":
                msg_custom_msg2 customMsg2 = (msg_custom_msg2) unpack;
                break;
            //  case "MAVLINK_MSG_ID_mission_msg1":
            case "MAVLINK_MSG_ID_MISSION_MSG1":
                msg_mission_msg1 msgMissionMsg1 = (msg_mission_msg1) unpack;
                break;
            // case "MAVLINK_MSG_ID_safeguard_msg":
            case "MAVLINK_MSG_ID_SAFEGUARD_MSG1":
                msg_safeguard_msg safeguardMsg = (msg_safeguard_msg) unpack;
                break;
            // case "MAVLINK_MSG_ID_ins_supplement":
            case "MAVLINK_MSG_ID_INS_SUPPLEMENT":
                msg_ins_supplement insSupplement = (msg_ins_supplement) unpack;
                break;
            case "MAVLINK_MSG_ID_STORAGE_INFORMATION":
                msg_storage_information storageInformation = (msg_storage_information) unpack;
                WsEndpoint.sendMessage(new WsDto().setSn(DroneCache.SERIAL_NUMBER_MAP.get(channel)).setFlag("storage").setDescription("总存储空间、剩余存储空间")
                        .setObject("total_storage", storageInformation.total_capacity, "remain_storage", storageInformation.available_capacity));
                break;
            default:
                break;
        }
    }
}
